import Card from '@/base/Card'
import Game from '@/base/Game'
import { Rank, Suit } from '@/types'
import { sortDoudizhuCard } from '@/utils'

class DoudizhuGame extends Game {
  remainingCards: Card[]

  constructor(players: string[]) {
    super(players)
    this.remainingCards = []
  }

  // 手牌排序
  sortPlayersHand() {
    this.players.forEach((player) => {
      player.hand = sortDoudizhuCard(player.hand)
    })
  }

  startGame() {
    super.startGame()

    // 斗地主发牌（3 人，每人 17 张，留底 3 张）
    this.players.forEach((player) => {
      player.receiveCards(this.deck.deal(17))
    })
    this.remainingCards = this.deck.deal(3)

    this.players.forEach((player) => {
      this.sortPlayersHand()
      console.log(`${player.name} 的手牌: ${player.hand}`)
    })

    console.log(
      `底牌: ${this.remainingCards.map((card) => card.toString()).join(', ')}`
    )
  }
}

export default DoudizhuGame
